import functools

from flask import session, current_app, g



def user_login(f):
    @functools.wraps(f)
    def wraps(*args,**kwargs):
        user_id = session.get('user_id')
        user = None
        if user_id:
            from info.models import User
            try:
                user = User.query.get(user_id)
            except  Exception as e:
                current_app.logger.error(e)
        g.user = user

        return f(*args,**kwargs)
    return wraps
